package com.hnevc.cnlizhimaomxbc;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.hnevc.cnlizhimaomxbc.util.DB;

public class LoginActivity extends AppCompatActivity {
    private EditText figure_et;
    private EditText cryptogram_et;
    private Button agree_bt;
    private String nameStr;
    private String passwordStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        initData();
        initEvent();

    }
    private void initView(){
        figure_et = (EditText) findViewById(R.id.figure_et);
        cryptogram_et = (EditText) findViewById(R.id.cryptogram_et);
        agree_bt = (Button) findViewById(R.id.agree_bt);

    }
    private void initData(){
        nameStr = figure_et.getText().toString() + "";
        passwordStr = cryptogram_et.getText().toString() + "";

    }
    private void initEvent() {
        agree_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (figure_et.getText().toString().length() >= 3) {
                    if (figure_et.getText().toString().length() > 5 && agree_bt.getText().toString().length() <= 15) {
                        Toast.makeText(LoginActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                        startActivity(intent);
                    } else {
                        Toast.makeText(LoginActivity.this, "两次密码不一样", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(LoginActivity.this, "密码格式不符合要求", Toast.LENGTH_SHORT).show();
                }

                DB db = new DB(LoginActivity.this);
                db.signInsert(nameStr, passwordStr);
            }
        });

    }
}

